package exam;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @Author 肖地洋
 * @Date 2022/7/16 11:33
 */
public class xinhuang {
    static int[][] nums;
    static int N;
    static int minlen = Integer.MAX_VALUE; //最短路径的长度
    static Set<String> set;//用来保存成功的路径，字符串表示：SXZY分别表示上下左右的行走方向
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        N = in.nextInt();
        nums = new int[N][N];
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                nums[i][j] = in.nextInt();
            }
        }
        set = new HashSet<>();
        dfs(new StringBuilder(),0,0);
        System.out.println(minlen==Integer.MAX_VALUE?0:minlen);
        int count =0;
        for(String s:set){
            if(s.length()==minlen) count++;
        }
        System.out.println(count);
    }

    public static void dfs(StringBuilder sb,int i,int j){ //sb为当前已经过的路径,i,j为当前位置坐标
        if(i==N-1&&j==N-1&&!set.contains(sb.toString())){
            minlen = Math.min(minlen,sb.length());
            set.add(sb.toString());
        }

        boolean s = i-1<0||nums[i-1][j]==0;//上
        boolean x = i+1>N-1||nums[i+1][j]==0;//下
        boolean z = j-1<0||nums[i][j-1]==0;//左
        boolean y = j+1>N-1||nums[i][j+1]==0;//右
        if(s&&x&&z&&y) return;  //上下左右都不能走了
        nums[i][j]=0;
        if(!s)  dfs(new StringBuilder(sb).append("S"),i-1,j);
        if(!x)  dfs(new StringBuilder(sb).append("X"),i+1,j);
        if(!z)  dfs(new StringBuilder(sb).append("Z"),i,j-1);
        if(!y)  dfs(new StringBuilder(sb).append("Y"),i,j+1);
        nums[i][j]=1;
    }
}